package com.isoft.airportsystem.service.impl;

import com.isoft.airportsystem.entity.DFDL.ARPT;
import com.isoft.airportsystem.entity.DFDL.DFLT;
import com.isoft.airportsystem.entity.DFDL.SFLT;
import com.isoft.airportsystem.entity.DFIE.MSG24;
import com.isoft.airportsystem.mapper.DfieMapper;
import com.isoft.airportsystem.service.DfieService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class DfieServiceImpl implements DfieService {

    @Resource
    private DfieMapper dfieMapper;

    @Override
    public void insert(MSG24 msg) {

        String dfie_uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();

        dfieMapper.addMeta(dfie_uuid, msg.getMeta());

        dfieMapper.addMSG(dfie_uuid);

        for (ARPT arpt : msg.getData().getARPT()) {
            dfieMapper.addArpt(dfie_uuid, arpt);
        }

        for (SFLT sflt : msg.getData().getSflt()) {
            dfieMapper.addSflt(dfie_uuid, sflt);
        }

        DFLT dflt = msg.getData();
        dfieMapper.addDflt(dfie_uuid, dflt, dflt.getCkls(), dflt.getTMCD());
    }

}
